package com.cml.rpc.client;

import com.cml.rpc.publicinterface.BlogService;
import com.cml.rpc.publicinterface.MemberService;
import com.cml.rpc.publicinterface.UserService;
import com.cml.rpc.publicpojo.Blog;
import com.cml.rpc.publicpojo.User;

/**
 *  客户端调用
 * @author cml
 * @create 2021/7/20 15:20
 */
public class RpcClient {
    public static void main(String[] args) {
        ClientProxy clientProxy = new ClientProxy("127.0.0.1", 8877);
        // 获取对应代理对象
        UserService userServiceProxy = clientProxy.getProxy(UserService.class);
        BlogService blogServiceProxy = clientProxy.getProxy(BlogService.class);
        MemberService memberServiceProxy = clientProxy.getProxy(MemberService.class);

        System.out.println("客户端调用UserService.getUserById........");
        User user = userServiceProxy.getUserById(123);
        System.out.println("接收来自服务端的user = " + user);

        System.out.println("-----------------------");
        System.out.println("客户端调用UserService.insertUser........");
        Integer result = userServiceProxy.insertUser(new User(1,"cml","12"));
        System.out.println("接收来自服务端的结果 = " + result);

        System.out.println("-----------------------");
        System.out.println("客户端调用MemberService.getMemberById........");
        User member = memberServiceProxy.getMemberById(520);
        System.out.println("接收来自服务端的member = " + member);

        System.out.println("-----------------------");
        System.out.println("客户端调用BlogService.insertUser........");
        Integer result1 = blogServiceProxy.insertBlog(new Blog(3, "博客", "博客内容"));
        System.out.println("接收来自服务端的结果 = " + result1);
    }
}
